/**
 * Created by ryansecreat on 2017/12/22.
 */
module.exports = app => {
    const { STRING, INTEGER, DATE } = app.Sequelize;

    const User = app.model.define('user', {
        id: {
            type: INTEGER,
            primaryKey: true,
            autoIncrement: true,
        },
        name: STRING(30),
        age: INTEGER,
        created_at: DATE,
        updated_at: DATE,
    });

    User.prototype.associate = function() {
        app.model.User.hasMany(app.model.Post, { as: 'posts', foreignKey: 'user_id' });
    };

    return User;
};
